<?php defined('BASEPATH') OR exit('No direct script access allowed');

class siteConfig extends wsBackend
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $data = array();

        $this->tpl->meta ['title'] = '网站设置 - ' . $this->config->item('site_name');
        $this->tpl->meta ['description'] = '';
        $this->tpl->meta ['keywords'] = '';
        $this->tpl->page_header = '网站设置';
        $this->tpl->page_header_ = '基本设置';
        $this->tpl->breadcrumbs['Site Config'] = 'active';


        $data['settings'] = $this->settings_model->get_AllSettings(false);
        if ($data['settings']) {
            $update = array();
            $post = $this->input->post('setting');
            if ($post) {
                foreach ($data['settings'] as $set) {
                    $update[] = array(
                        'setting_seq_id' => $set->setting_seq_id,
                        'setting_value' => (isset($post[$set->setting_seq_id]) ? $post[$set->setting_seq_id] : FALSE)
                    );
                }
                if (!empty($update))
                    $this->settings_model->update_BatchSettings($update, 'setting_seq_id');
                $this->session->set_flashdata('SUCCESS', '更新成功');
                $this->language->save_config();
                if (isset($post[$data['settings']['hashIDSession_key']->setting_seq_id]) && $data['settings']['hashIDSession_key']->setting_value != $post[$data['settings']['hashIDSession_key']->setting_seq_id]) {
                    $this->user->logOut();
                    $this->session->set_flashdata('SUCCESS', '更新成功，请重新登陆 :)');
                    redirect(admin_url('login'));
                }
                redirect(admin_url('siteConfig'));
            }
        }


        $this->tpl->contents [] = $this->tpl->fetch('contents/siteConfig', $data);
        $this->tpl->render();
    }


}
